﻿//References:
//http://msdn.microsoft.com/en-us/library/17sde2xt.aspx
//http://msdn.microsoft.com/en-us/library/wkzf914z.aspx
//http://msdn.microsoft.com/en-us/magazine/cc163533.aspx

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DelegateEvent
{
    public partial class DelegateEvent : Form
    {
        public delegate void ShowMessage(string message);
        public DelegateEvent()
        {
            InitializeComponent();
        }

        private void btnTestDelegate_Click(object sender, EventArgs e)
        {
            ShowMessage smDelegate = new ShowMessage(this.ShowMessageFunc);
            smDelegate("Called by a delegate");
        }

        public void ShowMessageFunc(string message)
        {
            MessageBox.Show(message);
        }

        private void btnTestSimpleCustomEvent_Click(object sender, EventArgs e)
        {
            //CounterOneToTen c = new CounterOneToTen();
            //c.CountedToFive += new EventHandler(c_CountedToFive);
            //c.StartCount();

            //CounterOneToTen2 c2 = new CounterOneToTen2();
            //c2.CountedToFive += new EventHandler(c_CountedToFive);
            //c2.StartCount();

            //CounterOneToTen3 c3 = new CounterOneToTen3();
            //c3.CountedToFive += new CounterOneToTen3.CustomEventHandler(c_CountedToFive);
            //c3.StartCount();

            CounterOneToTen4 c4 = new CounterOneToTen4();
            c4.CountedToFive += new CounterOneToTen4.CustomEventHandler(c_CountedToFive);
            c4.StartCount();
        }

        private void c_CountedToFive(object obj, EventArgs e)
        {
            MessageBox.Show("5");
        }
    }
}
